<template>
  <view class="content">
    <!-- 头部 -->
    <view class="header">
      <view class="headerimg">
        <img :src="currentUser.img" alt="" />
      </view>
      <view>手机号码:{{currentUser.phone}}</view>
      <view>ID:{{currentUser.id || '123456'}}</view>
    </view>
    <!-- 中间 -->
    <view class="middle">
      <view class="middlelist">
        <view class="middleitem" @click="myaddress">
          <img src="/static/imgs/addressme.png" alt="" style="height: 30px; width: 30px;" />
          我的地址
        </view>
        <view class="middleitem" @click="mylove">
          <img src="/static/imgs/loveme.png" alt="" style="height: 30px; width: 30px;" />
          我的关注
        </view>
        <view class="middleitem" @click="myorders">
          <img src="/static/imgs/cartme.png" alt="" style="height: 30px; width: 30px;" />
          我的订单
        </view>
      </view>
    </view>
    <!-- 底部 -->
    <view class="middlelogin">
      <button type="primary" @click="logout">退出登录</button>
    </view>
  </view>
</template>

<script>
import Config from '@/Config.js';

export default {
  data() {
    return {
      currentUser: {} // 当前登录用户信息
    };
  },
  onLoad() {
  },
  onShow() {
    // 从本地存储加载当前用户信息
    const user = uni.getStorageSync('currentUser');
    if (user) {
      this.currentUser = user;
    } else {
      // 如果未登录，跳转到登录页面
      uni.redirectTo({
        url: '/pages/login/login'
      });
    }
  },
  methods: {
    message() {
      uni.request({
        url: Config.api_host + `/users`,
        success: (res) => {
          this.users = res.data;
        }
      });
    },
    // 退出登录
    logout() {
      uni.showModal({
        title: '提示',
        content: '确定要退出登录吗？',
        success: (res) => {
          if (res.confirm) {
            // 清除用户信息
            uni.removeStorageSync('currentUser');
            // 跳转到登录页面
            uni.redirectTo({
              url: '/pages/login/login'
            });
          }
        }
      });
    },
    // 点击我的地址
    myaddress() {
      uni.navigateTo({
        url: '/pages/own/myaddress'
      });
    },
    // 点击我的关注
    mylove() {
      uni.navigateTo({
        url: '/pages/own/mylove'
      });
    },
    // 点击我的订单
    myorders() {
      uni.switchTab({
        url: '/pages/orders/index'
      });
    }
  }
};
</script>

<style scoped>
/* 整体页面 */
.content {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* 头部 */
.header {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 220px;
  background-color: rgb(17, 206, 240);
}

.headerimg {
  margin-top: 10px;
}

.headerimg img {
  margin-top: 30px;
  border-radius: 50%;
  height: 80px;
  width: 80px;
}

/* 中间 */
.middle {
  width: 100%;
}

.middlelist {
  padding-top: 20px;
  background-color: antiquewhite;
  height: 240px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.middleitem {
  width: 90%;
  height: 60px;
  background-color: aliceblue;
  border-radius: 4pt;
  border: 1px solid rgb(221, 216, 216);
  display: flex;
  align-items: center;
  padding-left: 20px;
  margin-bottom: 10px; /* 添加底部间距，使元素更清晰 */
}

/* 底部 */
.middlelogin {
  margin-top: 30px;
}
</style>